import React from 'react'
import { createRoot } from 'react-dom/client'
import { HashRouter, BrowserRouter } from 'react-router-dom'
import { ConfigProvider } from 'antd'
import App from '@/App'
import '@/style/index.scss'
import '@/icons'
import useStore from '@/store/index'
import { AliveScope } from 'react-activation'

let root = '' as any

function render(container: any) {
  root = createRoot(
    container
      ? container.querySelector('#root1')
      : (document.querySelector('#root1') as HTMLElement),
  )
  root.render(
    <AliveScope>
      <HashRouter basename={(window as any).__POWERED_BY_QIANKUN__ ? '/react-app1' : ''}>
        {/* prefixCls="nihao" */}
        <ConfigProvider>
          <App />;
        </ConfigProvider>
      </HashRouter>
    </AliveScope>,
  )
}
// console.log((window as any).__POWERED_BY_QIANKUN__, 12312312)
// 动态设置 webpack publicPath，防止资源加载出错
// if ((window as any).__POWERED_BY_QIANKUN__) {
//   console.log((window as any).__INJECTED_PUBLIC_PATH_BY_QIANKUN__, 'react')
//   __webpack_public_path__ = (window as any).__INJECTED_PUBLIC_PATH_BY_QIANKUN__
// }

// console.log(window.__POWERED_BY_WUJIE__, 'window.__POWERED_BY_WUJIE__')

if (window.__POWERED_BY_WUJIE__) {
  window.__WUJIE_MOUNT = () => {
    const {
      useUserStore: { setVueUserInfo, setToken },
      useGlobalStore: { changebaseName },
    } = useStore()
    // setVueUserInfo('nihao')
    // setVueUserInfo(props.vueUser)
    // setToken(window.$wujie.props.getToken())
    // window.$wujie
    render()
  }
  window.__WUJIE_UNMOUNT = () => {
    root.unmount()
  }
} else {
  render()
}
